package cn.fl.capital.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapFundVfLogRQueryCondition;
import cn.fl.capital.dto.CapFundVfLogRDTO;
import cn.fl.capital.service.ICapFundVfLogRApiService;
import cn.fl.capital.service.ICapFundVfLogRService;
import cn.fl.capital.transform.CapFundVfLogRVOTransform;
import cn.fl.capital.vo.CapFundVfLogRVO;
import cn.fl.framework.base.context.CurrentThreadContext;

/**
 * @Description: 客户资金与核销记录关联表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class CapFundVfLogRServiceImpl implements ICapFundVfLogRService {

	/**
     * 日志
     */
    @SuppressWarnings("unused")
    private static final Logger logger = LoggerFactory.getLogger(CapFundVfLogRServiceImpl.class);
	
	/**
	 * 客户资金与核销记录关联表 暴露服务
	 */
	@Autowired
	private ICapFundVfLogRApiService capFundVfLogRApiService;
	/**
     * 数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

	@Override
	public CapFundVfLogRVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)) return null;
		CapFundVfLogRDTO dto = this.capFundVfLogRApiService.selectCapFundVfLogRById(id);
		return CapFundVfLogRVOTransform.toVO(dto);
	}

	@Override
	public Long add(CapFundVfLogRVO entity) throws BaseException{
		if(null == entity) return null;
		return this.capFundVfLogRApiService.addCapFundVfLogR(CapFundVfLogRVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeByIds(List<Long> ids) throws BaseException{
		if(CollectionUtils.isEmpty(ids)) return false;
		return this.capFundVfLogRApiService.removeCapFundVfLogRByIds(ids,CurrentThreadContext.getCurrentUserId());
	}

	@Override
	public boolean modify(CapFundVfLogRVO entity) throws BaseException{
		if(null == entity) return false;
		return this.capFundVfLogRApiService.modifyCapFundVfLogR(CapFundVfLogRVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
        CapFundVfLogRQueryCondition condition=null;
        if(null == page) {
            page = new Pager();
            page.setCondition(new CapFundVfLogRQueryCondition());
        }
		condition=(CapFundVfLogRQueryCondition)page.getCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		page=this.capFundVfLogRApiService.searchCapFundVfLogRListPage(page);
		if(CollectionUtils.isNotEmpty(page.getResultList())){
            List<CapFundVfLogRVO> voList=CapFundVfLogRVOTransform.toVOList((List<CapFundVfLogRDTO>)page.getResultList());
            //this.setDictData(voList);
            page.setResultList(voList);
        }
        return page;
	}
	
	@Override
	public List<CapFundVfLogRVO> searchList(CapFundVfLogRQueryCondition condition) throws BaseException{
		if(null == condition) condition=new CapFundVfLogRQueryCondition();
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
		condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		List<CapFundVfLogRVO> voList=CapFundVfLogRVOTransform.toVOList(this.capFundVfLogRApiService.searchCapFundVfLogRList(condition));
		this.setDictData(voList);
		return voList;
	}
	
    /**
     * 添加数据字典名称
     * @param voList
     */
	public void setDictData(List<CapFundVfLogRVO> voList){
		if(CollectionUtils.isEmpty(voList)) return;
		/*Map<String, String> _CdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, CapFundVfLogRConstant.CODE_CD);
		for(CapFundVfLogRVO vo:voList){
			if (_CdMap != null && _CdMap.containsKey(vo.getCd())) {
            	vo.setCdNm(_CdMap.get(vo.getCd()));
        	}	
		}*/
	}
	
	/**
     * 查询数据字典
     * @param groupCd 组代码
     * @return List<KeyValueVO>
     */
    public List<KeyValueVO> searchCdList(String groupCd){
        return this.sysDictionaryApiService.getKvList(groupCd, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

    
    /**
     * 根据集合查询表中所有数据
     * @param condition
     * @return
     * @throws BaseException
     */
	@Override
	public List<CapFundVfLogRVO> searchVList(List<Long> idsList) throws BaseException {
		List<CapFundVfLogRVO> voList =null;
		if(CollectionUtils.isNotEmpty(idsList)){
			 List<CapFundVfLogRDTO> searchTypeVfLogRList = this.capFundVfLogRApiService.searchTypeVfLogRList(idsList);
		          voList = CapFundVfLogRVOTransform.toVOList(searchTypeVfLogRList);
		}
		 return voList;
	}
	    
}
